// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Element/CBEAMParser.h"

#include "gtest/gtest.h"

#include "DataStructure/Input/Element/BeamCoordOptions.h"
#include "DataStructure/Input/Element/CBEAMData.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure::FEM;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class CBEAMParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

// 数据库管理器

TEST_F (CBEAMParserTest, ParserEntry)
{
    std::vector<std::string> Entry = { "CBEAM   1       11      1       2       0.      1.      0.      BGG     +0000023",
                                       "+0000023                2.367   0.      0.      1.184   0.      0.",
                                       "        101     102 " };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCBEAM (DB_SERVICEFACTORY, dividedEntryInfo);

    // 测试数据
    SG::DataStructure::FEM::CBEAMData   data;
    std::vector<BeamCoordOptions> const dataGetCoordOptionsTarget{ SG::DataStructure::FEM::BeamCoordOptions::OPTION_B,
                                                                   SG::DataStructure::FEM::BeamCoordOptions::OPTION_G,
                                                                   SG::DataStructure::FEM::BeamCoordOptions::OPTION_G };
    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (0, data);

    ASSERT_TRUE (data.m_id == 1);
    ASSERT_TRUE (data.m_pId == 11);
    ASSERT_TRUE (data.m_g[0] == 1);
    ASSERT_TRUE (data.m_g[1] == 2);
    ASSERT_TRUE (data.GetCoordOptions () == dataGetCoordOptionsTarget);
    ASSERT_EQ (data.m_go, 0);
    ASSERT_NEAR (data.m_w1a, 2.367, TOLERANCE);
    ASSERT_NEAR (data.m_w2a, 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_w3a, 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_w1b, 1.184, TOLERANCE);
    ASSERT_NEAR (data.m_w2b, 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_w3b, 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_x1, 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_x2, 1.0, TOLERANCE);
    ASSERT_NEAR (data.m_x3, 0.0, TOLERANCE);
    ASSERT_TRUE (data.m_sa == 101);
    ASSERT_TRUE (data.m_sb == 102);
}
